package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ActivationCodes;
import com.ruoyi.system.service.IActivationCodesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 激活码增删改查Controller
 *
 * @author 何志龙
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/system/ActivationCodes")
public class ActivationCodesController extends BaseController
{
    @Autowired
    private IActivationCodesService activationCodesService;

    /**
     * 查询激活码增删改查列表
     */
    @PreAuthorize("@ss.hasPermi('system:ActivationCodes:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivationCodes activationCodes)
    {
        startPage();
        List<ActivationCodes> list = activationCodesService.selectActivationCodesList(activationCodes);
        return getDataTable(list);
    }

    /**
     * 导出激活码增删改查列表
     */
    @PreAuthorize("@ss.hasPermi('system:ActivationCodes:export')")
    @Log(title = "激活码增删改查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivationCodes activationCodes)
    {
        List<ActivationCodes> list = activationCodesService.selectActivationCodesList(activationCodes);
        ExcelUtil<ActivationCodes> util = new ExcelUtil<ActivationCodes>(ActivationCodes.class);
        util.exportExcel(response, list, "激活码增删改查数据");
    }

    /**
     * 获取激活码增删改查详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ActivationCodes:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activationCodesService.selectActivationCodesById(id));
    }

    /**
     * 新增激活码增删改查
     */
    @PreAuthorize("@ss.hasPermi('system:ActivationCodes:add')")
    @Log(title = "激活码增删改查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivationCodes activationCodes)
    {
        return toAjax(activationCodesService.insertActivationCodes(activationCodes));
    }

    /**
     * 修改激活码增删改查
     */
    @PreAuthorize("@ss.hasPermi('system:ActivationCodes:edit')")
    @Log(title = "激活码增删改查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivationCodes activationCodes)
    {
        return toAjax(activationCodesService.updateActivationCodes(activationCodes));
    }

    /**
     * 删除激活码增删改查
     */
    @PreAuthorize("@ss.hasPermi('system:ActivationCodes:remove')")
    @Log(title = "激活码增删改查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activationCodesService.deleteActivationCodesByIds(ids));
    }
}
